package com.qf.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@WebServlet("/testSession")
public class SessionServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        System.out.println("session  --  get");
        HttpSession session = req.getSession();
        String url = resp.encodeRedirectURL("/view");
        System.out.println(url);
//        System.out.println("sessionID:"+session.getId());
        //在session域中存储数据
        System.out.println("在session域中存储数据");
        session.setAttribute("sessiondata", "session域中的数据");

//        resp.getWriter().println("success");

        //对 原路径进行处理， 在路径参数上拼接 sessionID


        resp.sendRedirect(url);
    }
}
